<?php
include_once("../module/checkA.php");
include_once("../../config.php");
$plate=select_one_line_all_items($table_Prefix."plate","mid = 'finance'");
?>



<?
//用来判断当前系统属于什么板块
$system_part = $plate['mid'];
?>
 
<?
//这个是发工资的快捷方式。
if($_REQUEST['action']=="salary")
{

    $employee=select_one_line_all_items($table_Prefix."employee","nid = '".$_REQUEST['nid']."'");
    $name=$employee['name'].date('m',strtotime('midnight first day of -1 month'))."月份工资";
    $cost=-$employee['salary'];
    $classify="工资支出";

}


if($_REQUEST['action']=="commission")
{

    $employee=select_one_line_all_items($table_Prefix."employee","nid = '".$_REQUEST['nid']."'");
    $name=$employee['name'].date('m',strtotime('midnight first day of -1 month'))."月份提成";

    $workerid=$employee['nid'];


//经过复杂的计算，计算出上一个月的提成
$last_month=date('Y-m',strtotime('midnight first day of -1 month'));

$case_list2 = select_lines_all_items($table_Prefix . "case", "nid desc", "
(agent     ='" . $workerid . "' or
respon    ='" . $workerid . "' or
sales     ='" . $workerid . "' or
service   ='" . $workerid . "' or
designer  ='" . $workerid . "' or
programer ='" . $workerid . "' or
editor    ='" . $workerid . "') and startdate > '2018-12-31 23:59:59' and paydate like '".$last_month."%' ", "");


$case_id_list2=transform_2darray_in_1darray_number_as_key($case_list2,"nid");

$case_id_list_srt2=implode(",", $case_id_list2);

$bonus_list2 = select_lines_all_items($table_Prefix . "bonus_record", "nid desc", "caseid in (".$case_id_list_srt2.")", "0");

foreach($bonus_list2 as $k => $v)
{
    $case_bonus2[$v['caseid']]=$v;
}


for($i=0;$i<count($case_list2);$i++)
{

        if($case_bonus2[$case_list2[$i]['nid']]['agent']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['agent_bonus'];
                $sum_agent2[]=$case_bonus2[$case_list2[$i]['nid']]['agent_bonus'];}

        if($case_bonus2[$case_list2[$i]['nid']]['sales']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['sales_bonus'];
                $sum_sales2[]=$case_bonus2[$case_list2[$i]['nid']]['sales_bonus'];}

        if($case_bonus2[$case_list2[$i]['nid']]['respon']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['respon_bonus'];
                $sum_respon2[]=$case_bonus2[$case_list2[$i]['nid']]['respon_bonus'];}

        if($case_bonus2[$case_list2[$i]['nid']]['service']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['service_bonus'];
                $sum_service2[]=$case_bonus2[$case_list2[$i]['nid']]['service_bonus'];}

        if($case_bonus2[$case_list2[$i]['nid']]['designer']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['designer_bonus'];
                $sum_designer2[]=$case_bonus2[$case_list2[$i]['nid']]['designer_bonus'];}

        if($case_bonus2[$case_list2[$i]['nid']]['programer']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['programer_bonus'];
                $sum_programer2[]=$case_bonus2[$case_list2[$i]['nid']]['programer_bonus'];}

        if($case_bonus2[$case_list2[$i]['nid']]['editor']==$workerid){echo $case_bonus2[$case_list2[$i]['nid']]['editor_bonus'];
                $sum_editor2[]=$case_bonus2[$case_list2[$i]['nid']]['editor_bonus'];}
}


$bonus=array_sum($sum_agent2)+array_sum($sum_sales2)+
       array_sum($sum_respon2)+array_sum($sum_service2)+
       array_sum($sum_designer2)+array_sum($sum_programer2)+
       array_sum($sum_editor2);

    $cost=-$bonus;
    $classify="提成支出";

}





if($_REQUEST['action']=="bonus")
{

    $employee=select_one_line_all_items($table_Prefix."employee","nid = '".$_REQUEST['nid']."'");
    $name=$employee['name'].date('m',strtotime('midnight first day of -1 month'))."月份奖金支出";
    $cost="-100";
    $classify="奖金支出";

}

; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include_once(ROOT_PATH_.'/controlbase/module/head.php'); ?>


	
</head>

<body>

<div id="topbar">
    <?php include ROOT_PATH_ . '/controller/common/module/topbar.php'; ?>
</div>

<div id="container" class="member">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_ . '/controller/common/module/sidebar.php'; ?>
        </div>


    <div id="content">
        <?php $page_title='新增财务信息';?>
        <?php include ROOT_PATH_.'/controlbase/module/mod-page-title.php'; ?>




<div class="flash_box">
<!--    <div>采购物料账目，请从<a href="--><?//echo $domain?><!--/controlbase/inventory/detail-list.php?nav-itemed=material">进销存系统</a>中录入。</div>-->
    <div>采购物料账目，请从进销存系统(暂未开放)中录入。</div>
</div>


<form id="add-member-form" method="post" action="detail-add-function.php?nav-itemed=finance" enctype="multipart/form-data" class="layui-form detail-box">


    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <input type="text" name="ai_name" lay-verify="required" placeholder="请输入内容" autocomplete="off"
                   class="layui-input" value="<?echo $name?>">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">金额</label>
        <div class="layui-input-block">
            <input type="text" name="ai_cost" lay-verify="required" placeholder="请输入金额" autocomplete="on" class="layui-input" value="<?echo $cost?>">
        </div>
    </div>






    <div class="layui-form-item">
        <label class="layui-form-label">日期</label>
        <div class="layui-input-block">
            <input type="text" name="ai_applydate" id="date" autocomplete="off" class="layui-input"  value="<?echo date("Y-m-d H:i:s")?>" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" class="laydate-icon">
        </div>
    </div>





    <?
    $principal_list=select_lines_all_items($table_Prefix."employee","nid desc","","0");
    ?>

    <div class="layui-form-item">
        <label class="layui-form-label">用款人</label>
        <div class="layui-input-block">
            <select name="ai_principal" lay-search="">

                <?if ($employee){?>
                    <option value="<? echo $employee['nid'] ?>"><? echo $employee['mid'] ?> : <? echo $employee['name'] ?></option>
                <?;}?>

                <option  value="无" > 无</option>

                <? for($i=0;$i<count($principal_list);$i++){ ?>
                    <option value="<? echo $principal_list[$i]['nid'] ?>"><? echo $principal_list[$i]['mid'] ?> : <? echo $principal_list[$i]['name'] ?></option>
                <? } ?>
            </select>
        </div>
    </div>



<!--    --><?//
//    $unit_list=select_lines_all_items($table_Prefix."unit","nid desc","relation = '客户'","0");
//    $unit=select_one_line_all_items($table_Prefix."unit","nid = '".$detail['unit']."'");
//    ?>
<!---->
<!---->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">用款单位</label>-->
<!--        <div class="layui-input-block">-->
<!--            <select name="ai_unit"  lay-search="" >-->
<!--                --><?//if ($employee){?>
<!--                    <option value="325">圆点设计</option>-->
<!--                    --><?//;}?>
<!--                <option value="">无</option>-->
<!--                --><?// for($i=0;$i<count($unit_list);$i++){ ?>
<!--                    <option value="--><?// echo $unit_list[$i]['nid'] ?><!--">--><?// echo $unit_list[$i]['nid'] ?><!-- : --><?// echo $unit_list[$i]['name'] ?><!--</option>-->
<!--                --><?// } ?>
<!--            </select>-->
<!--        </div>-->
<!--    </div>-->





    <div class="layui-form-item">
        <label class="layui-form-label">用途</label>
        <div class="layui-input-block">
            <select name="ai_classify" >
                <option value="<?echo $classify?>"><?echo $classify?></option>
                <option value="公众号续费收入">公众号续费收入</option>
                <option value="域名续费收入">域名续费收入</option>
                <option value="服务器续费收入">服务器续费收入</option>
                <option value="票务">票务</option>
                <option value="域名续费支出">域名续费支出</option>
                <option value="服务器续费支出">服务器续费支出</option>

                <option value="项目损耗">项目损耗</option>
                <option value="快递费">快递费</option>


                <option value="工资支出">工资支出</option>
                <option value="交通补贴支出">交通补贴支出</option>
                <option value="奖金支出">奖金支出</option>
                <option value="提成支出">提成支出</option>

                <option value="行政支出">行政支出</option>

                <option value="水电费">水电费</option>
                <option value="租赁费">租赁费</option>

                <option value="其他">其他</option>
            </select>
        </div>
    </div>


<!---->
<!---->
<!--    --><?//
//    $case_list=select_lines_all_items($table_Prefix."case","nid desc","status ='进行中' or status = '未开始' ","0");
//    $case=select_one_line_all_items($table_Prefix."case","nid = '".$detail['caseid']."'");
//    ?>
<!---->
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">项目</label>-->
<!--        <div class="layui-input-block">-->
<!--            <select name="ai_caseid" >-->
<!--                <option value="">无</option>-->
<!--                --><?//for($i=0;$i<count($case_list);$i++){?>
<!--                    <option value="--><?// echo $case_list[$i]['nid'] ?><!--">--><?// echo $case_list[$i]['name'] ?><!--</option>-->
<!--                --><?// } ?>
<!--            </select>-->
<!--        </div>-->
<!--    </div>-->
<!---->
<!---->
<!---->
<!---->
<!---->
<!--    --><?//
//        if(($_SESSION['mid']!="admin")&&($_SESSION['mid']!="admin"))
//        {
//
//        }
//else{
//        $department_list=select_lines_all_items($table_Prefix."department","nid desc","","0");
//}
//        ?>
<!---->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">部门</label>-->
<!--            <div class="layui-input-block">-->
<!--                <select name="ai_departmentid" >-->
<!---->
<!--                    <option value="--><?// echo $_SESSION['departmentid'] ?><!--">--><?//echo $userdepartment['name'] ?><!--</option>-->
<!---->
<!--                    --><?//for($i=0;$i<count($department_list);$i++){?>
<!--                        <option value="--><?// echo $department_list[$i]['nid'] ?><!--">--><?// echo $department_list[$i]['name'] ?><!--</option>-->
<!--                    --><?// } ?>
<!--                </select>-->
<!--            </div>-->
<!--        </div>-->
<!---->
<!---->
<!---->
<!---->


    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block" >
            <input type="radio" name="ai_status" value="待收款" title="待收款" <? if ($detail['status'] == "待收款") {
                echo "checked";
            } ?>>
            <input type="radio" name="ai_status" value="已收款" title="已收款" <? if ($detail['status'] == "已收款") {
                echo "checked";
            } ?>>
            <input type="radio" name="ai_status" value="烂账" title="烂账" <? if ($detail['status'] == "烂账") {
                echo "checked";
            } ?>>
            <input type="radio" name="ai_status" value="其他" title="其他" <? if ($detail['status'] == "其他") {
                echo "checked";
            } ?>>
        </div>

    </div>






        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="ai_remark" placeholder="备注" class="layui-textarea">  </textarea>
            </div>
        </div>






        <input name="now_extender" type="hidden" value="<? echo $system_part ?>"/>
        <input name="nowpageid" type="hidden" value="<? echo $_REQUEST['nowpageid'] ?>"/>
        <input name="sortby" type="hidden" value="<? echo $_REQUEST['sortby'] ?>"/>










        <div class="function">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formMemberAdd" type="submit">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 


 
 
        </div>
		
 
 
<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>








<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?> </body>
</html>
